﻿#pragma once
#include "QCustomplot.h"

class PlotValueTracer;
struct TrendLine
{
	QCPGraph* waveLine = nullptr;
	QCPItemStraightLine* LSL_Line	   = nullptr; //<! 规格下限参考线
	QCPItemStraightLine* USL_Line	   = nullptr; //<! 规格上限参考线
	QCPItemStraightLine* Standard_Line = nullptr; //<! 标准值参考线

	QPointer<PlotValueTracer> tag;     //游标
	QPointer<PlotValueTracer> vtrac;   //数值游标
};
class QTrendChart :public QCustomPlot
{
	Q_OBJECT
public:
	QTrendChart(int y_min,int y_max,QWidget* parent = nullptr);
	virtual ~QTrendChart();

	//设置波形曲线，不存在该名字则新增
	void setWaveLine(QString name,QColor color);
	//删除波形图
	void deleteWaveLine(QString name);

	//设置参考线，不存在该名字则新增
	// 索引 1(LSL)，2(USL),3(Standard)
	void setReferenceLine(QString name,int idx,QColor color,double y_value);
	//删除参考线
	void deleteReferenceLine(QString name, int idx);
private:
	void createValueTracer(TrendLine& trend);
public slots:
	void plotData(QString waveLinename, double xValue, double value);
	void reset();

	void slotShowValueTracer(QMouseEvent* event);  //显示数值游标
	void slotHideValueTracer(QMouseEvent* event);
private:
	QMap<QString, TrendLine> trendLineMap;

};